package com.itheima.aop;

import com.itheima.domain.Equipment;
import com.itheima.domain.Order;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Aspect
public class EquipmentInfoAop {

    /**
     * 切入点表达式
     */
    @Pointcut("execution(* com.itheima.service.impl.EquipmentServiceImpl.add*(..))")
    public void pt(){}


    /**
     * 通知方法
     */
    @Around("pt()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        //1.获取方法的参数
        Object[] args = pjp.getArgs();
        //2.给方法的参数添加createTime  updateTime 的数据
        Equipment equipment = (Equipment) args[0];
        equipment.setUpdated(new Date());
        equipment.setCreated(new Date());
        //3.执行方法
        Object proceed = pjp.proceed(args);
        return proceed;
    }
}
